package com.ww.java.generic.wildcard.unbound;

import java.util.ArrayList;
import java.util.List;

/**
 * 有很多情况都和你在这里看到的情况类似，即编译器很少关心使用的是原生类型还是<?>。在这些情况中，
 * <?>可以被认为是一种装饰，但是它仍旧是很有价值的，因为，实际上，它是在声明“我是想用Java泛型来
 * 编写这段代码，我在这里并不是要用原生类型，但是在当前这种情况下，泛型参数可以持有任何类型”。
 */
public class UnboundedWildcards1 {

	@SuppressWarnings("rawtypes")
	static List list1;
	
	static List<?> list2;
	
	static List<? extends Object> list3;
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	static void assign1(List list) {
		list1 = list;
		list2 = list;
		// Warning
		// Type safety: The expression of type List needs unchecked conversion to conform to List<? extends Object>
		list3 = list;
	}
	
	static void assign2(List<?> list) {
		list1 = list;
		list2 = list;
		list3 = list;
	}
	
	static void assign3(List<? extends Object> list) {
		list1 = list;
		list2 = list;
		list3 = list;
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static void main(String[] args) {
		assign1(new ArrayList());
		assign2(new ArrayList());
		// Warning
		// Type safety: The expression of type ArrayList needs unchecked conversion to conform to List<? extends Object>
		assign3(new ArrayList());
		
		assign1(new ArrayList<String>());
		assign2(new ArrayList<String>());
		assign3(new ArrayList<String>());
		
		List<?> wildList = new ArrayList<>();
		wildList = new ArrayList<>();
		assign1(wildList);
		assign2(wildList);
		assign3(wildList);
	}
}
